import axios from "axios";

const request = axios.create({
    baseURL: "http://47.94.6.186:3001",
    timeout: 5000,
    headers: {
        token: localStorage.getItem('token') || ''
    }
})

// 请求拦截器，确保每次请求都带上最新的token
request.interceptors.request.use(
    config => {
        // 每次发送请求前检查 localStorage 中的 token 是否存在
        const token = localStorage.getItem('token');
        if (token) {
            config.headers.token = token;
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

export default request
